package cn.azy.activemq.consumer.utils;

import cn.azy.activemq.entity.Message;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

/**
 * @ Author     ：AZY.
 * @ Date       ：Created in 10:38 2019/10/21
 * @ Description：${DESCRIPTION}
 */
@Slf4j
public class UrlUtil {

    public static void Connect(Message msg) throws IOException {
        String urlstr = "http://127.0.0.1:8085/websocket/sendmsg/?msg="+URLEncoder.encode(msg.getMsg(),"utf-8")+"&username="+msg.getUsername();
        log.info(urlstr);
        URL url = new URL(urlstr);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("accept", "*/*");
        connection.setRequestProperty("connection", "Keep-Alive");
        connection.setRequestProperty("user-agent",
                "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36");
        connection.setRequestProperty("Accept",
                "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3");
        connection.connect();
        log.info(connection.getResponseCode()+"");
    }
}
